<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

import commentTypeUtil from "../comment/commentTypeUtil.vue";
import commentTextUtil from "../comment/commentTextUtil.vue";
import reqApis from '../../../req/reqApis.js';

const router = useRouter();

const props = defineProps({
  list:{
    type:Array
  }
});

const currentData = ref<any>({
  productId: router.currentRoute.value.query.productId,
  commentObj: {},
});

const getCommentTotalFn = () => {
  reqApis.getCommentTotalByProductIdApi({
    productId: currentData.value.productId,
  }).then((res:any) => {
    currentData.value.commentObj = res.data;
    console.log(11, currentData.value.commentObj)
  })
};

const toComment = () => {
  router.push({path: "/comment", query: {productId: currentData.value.productId}});
};

getCommentTotalFn();
</script>
<template>
  <section class="prodcutCommentUtil">
    <div class="title-wrap" @click="toComment()">
      <div class="l-wrap"> 评价<span>好评{{currentData.commentObj.score}}%</span></div>
      <div class="r-wrap"><span>共 {{currentData.commentObj.total}} 条</span><i></i></div>
    </div>
    <div class="content">
      <commentTypeUtil :selectBool="false" :commentObj="currentData.commentObj"></commentTypeUtil>
      <commentTextUtil :comment="item" v-for="(item,index) in props.list" :key="index"></commentTextUtil>
      <!-- <div class="comment-type">
        <div class="item">好评(3)</div>
        <div class="item">中评(0)</div>
        <div class="item">差评(0)</div>
      </div> -->
      <!-- <div class="comment">
        <div class="user-wrap">
          <div class="name">夜游神之夜猫</div>
          <div class="time">2018-12-28</div>
        </div>
        <div class="text">没有见过这么漂亮的商品，非常完美.从来没有见过这么漂亮的商品，非常完美。从来没有见过这么漂亮的商品，非常完美。从来没有见过这么漂亮的商品，非常完美</div>
      </div>
      <div class="comment">
        <div class="user-wrap">
          <div class="name">夜游神之夜猫</div>
          <div class="time">2018-12-28</div>
        </div>
        <div class="text">没有见过这么漂亮的商品，非常完美.从来没有见过这么漂亮的商品，非常完美。从来没有见过这么漂亮的商品，非常完美。从来没有见过这么漂亮的商品，非常完美</div>
      </div> -->
      <div class="btn-wrap">
        <div class="btn" @click="toComment()">查看全部评论</div>
      </div>
    </div>
  </section>
</template>

<style lang="less" scoped>
.prodcutCommentUtil {
  width: 3.75rem;
  background: white;
  margin-bottom: .1rem;
  .title-wrap {
    padding: 0 .1rem;
    height: .4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .14rem;
    color: #333;
    position: relative;
    &::after {
      width: 100%;
      height: 0rem;
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      border-bottom:  .01rem solid #ddd;
    }
    .l-wrap {
      span {
        font-size: 12px;
        color: #e4393c;
        padding-left: .1rem;
      }
    }
    .r-wrap {
      display: flex;
      align-items: center;
      font-size: .14rem;
      i {
        width: .4rem;
        height: .4rem;
        background: url("../../../assets/images/more-icon-3.png") no-repeat center;
        background-size: 60%;
      }
    }
    
  }
  .comment-type {
    padding: .14rem .1rem 0;
    display: flex;
    .item {
      height: .25rem;
      line-height: .25rem;
      padding: 0 .05rem;
      background: #fdf0f0;
      margin-right: .1rem;
      font-size: .12rem;
      border-right: .1rem;
      border-radius: .04rem;
    }
  }
  .comment {
    padding: 0 .1rem .1rem;
    position: relative;
    &::after {
      width: 100%;
      height: 0rem;
      content: "";
      border-bottom: 1px solid #ddd;
      position: absolute;
      bottom: 0;
      left: 0;
    }
    .user-wrap {
      padding-top: .1rem;
      font-size: .12rem;
      color: #999;
      display: flex;
      justify-content: space-between;
    }
    .text {
      padding: .05rem 0;
      font-size: 12px;
      color: #333;
      word-break: break-all;
    }
  }
  .btn-wrap {
    height: .45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    .btn {
      width: .85rem;
      height:.25rem;
      line-height: .25rem;
      font-size: .12rem;
      text-align: center;
      color: #333;
      position: relative;
      &::after {
        position: absolute;
        content: "";
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        border-radius: .1rem;
         border: .01rem solid #ddd;
      }
     
    }
  }
}
</style>

